#include "58StudentClassI.hpp"
#include <iostream>
#include <string>
#include <valarray>

std::ostream &StudentClassI::arr_out(std::ostream &os) const
{
    int i;
    int lim = ArrayDb::size();
    if (lim > 0)
    {
        for (i = 0; i < lim; i++)
        {
            os << ArrayDb::operator[](i) << " ";
            if (i % 5 == 4)
                os << std::endl;
        }
        if (i % 5 != 0)
            os << std::endl;
    }
    else
        os << " empty array ";
    return os;
}

double StudentClassI::Average() const
{
    if (ArrayDb::size() > 0)
        return ArrayDb::sum() / ArrayDb::size();
    else
        return 0;
}
double &StudentClassI::operator[](int i)
{
    return ArrayDb::operator[](i); // use ArrayDb::operator[]()
}
double StudentClassI::operator[](int i) const
{
    return ArrayDb::operator[](i); // use ArrayDb::operator[]()
}
const std::string &StudentClassI::Name() const
{
    return (const std::string &)*this;
}

// friends
// use String version of operator>>()
std::istream &operator>>(std::istream &is, StudentClassI &stu)
{
    is >> (std::string &)stu;
    return is;
}

// use string friend getline(ostream &, const string &)
std::istream &getline(std::istream &is, StudentClassI &stu)
{
    getline(is, (std::string &)stu);
    return is;
}

// use string version of operator<<()
std::ostream &operator<<(std::ostream &os, const StudentClassI &stu)
{
    os << "Scores for " << (const std::string &)stu << ":\n";
    stu.arr_out(os); // use private method for scores
    return os;
}
